package com.ywjt.platformbusiness.my;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseVPFragment;
import com.ywjt.platformbusiness.classify.activity.ShopHomeDetailActivity;
import com.ywjt.platformbusiness.common.UserData;
import com.ywjt.platformbusiness.login.LoginActivity;
import com.ywjt.platformbusiness.my.activity.ActivityAddress;
import com.ywjt.platformbusiness.my.activity.ActivityApplyteam;
import com.ywjt.platformbusiness.my.activity.ActivityFeedBack;
import com.ywjt.platformbusiness.my.activity.ActivityMyQrCode;
import com.ywjt.platformbusiness.my.activity.ActivityNickNameModify;
import com.ywjt.platformbusiness.my.activity.ActivityRelativeUs;
import com.ywjt.platformbusiness.my.activity.ActivityServiceCenter;
import com.ywjt.platformbusiness.my.activity.ActivitySet;
import com.ywjt.platformbusiness.my.activity.ActivitySign;
import com.ywjt.platformbusiness.my.activity.CouponActivity;
import com.ywjt.platformbusiness.my.activity.MyBalanceActivity;
import com.ywjt.platformbusiness.my.activity.MyExtendStoreActivity;
import com.ywjt.platformbusiness.my.activity.MyIntegralActivity;
import com.ywjt.platformbusiness.order.activity.ActivityOrderList;
import com.ywjt.platformbusiness.store.activity.MyStoreActivity;
import com.ywjt.platformbusiness.util.PictureUtils;
import com.ywjt.platformbusiness.util.SPUtils;
import com.ywjt.platformbusiness.widget.ApplyPickBottomDialog;

public class MyIndex extends BaseVPFragment implements View.OnClickListener {
    private Context context;
    private View view;
    private TextView tvNickName,tvAllOrder,tvBalance,tvSliverIntegral;
    private ImageView ivSet,ivChange,ivAvatar;
    private LinearLayout llMyProperty,llIntegralSilver,
            llRelativeUs,llServiceCenter,llAddressManager
            ,llMyExtendStore,llFeedBack,llApplyStore,llApplyTeam,
            llMyQrCode,llCoupon,llSign;
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.llSign:
                ActivitySign.actionStart(context);
                break;
            case R.id.ivSet:
                ActivitySet.actionStart(context);
                break;
            case R.id.llMyProperty:
                MyBalanceActivity.actionStart(context);
                break;
            case R.id.tvNickName:
                ActivityNickNameModify.actionStart(context);
                break;
            case R.id.llIntegralSilver:
                MyIntegralActivity.actionStart(context);
                break;
            case R.id.llRelativeUs:
                ActivityRelativeUs.actionStart(context);
                break;
            case R.id.llServiceCenter:
                ActivityServiceCenter.actionStart(context);
                break;
            case R.id.llAddressManager:
                ActivityAddress.actionStart(context,1);
                break;
            case R.id.tvAllOrder:
                ActivityOrderList.actionStart(context);
                break;
            case R.id.llMyExtendStore:
                MyExtendStoreActivity.actionStart(context);
                break;
            case R.id.llFeedBack:
                ActivityFeedBack.actionStart(context);
                break;
            case R.id.llApplyStore:
                //我的店铺
              //  ShopHomeDetailActivity.actionStart(context);
                break;
            case R.id.llApplyTeam:
                ActivityApplyteam.actionStart(context);
                break;
            case R.id.ivChange:
                //切换身份
                MyStoreActivity.actionStart(context);
                break;
            case R.id.llMyQrCode:
                ActivityMyQrCode.actionStart(context);
                break;
            case R.id.llCoupon:
                CouponActivity.actionStart(context);
                break;
        }
    }

    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {
        if (isVisible){
            if (!SPUtils.getSharedBooleanData(context,"isLogin")){
                LoginActivity.actionStart(context);
            }else {
                Glide.with(context).load(UserData.create(context).get(UserData.AVATAR))
                        .placeholder(R.mipmap.default_headlink)
                        .apply(new RequestOptions().transform(new PictureUtils()))
                        .into(ivAvatar);
                tvNickName.setText(UserData.create(context).get(UserData.NICKNAME));
                tvBalance.setText(UserData.create(context).get(UserData.BALANCE));
                tvSliverIntegral.setText(UserData.create(context).get(UserData.SILVERINTEGRAL));
            }
        }
    }

    @Override
    protected void onFragmentFirstVisible() { }

    public static MyIndex newInstance(String content) {
        Bundle arguments = new Bundle();
        arguments.putString("string", content);
        MyIndex fl = new MyIndex();
        fl.setArguments(arguments);
        return fl;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.my_index, container, false);
            context = getActivity();
            initView();
        }
        return view;
    }

    public void initView(){
        llMyProperty=view.findViewById(R.id.llMyProperty);
        ivSet=view.findViewById(R.id.ivSet);
        ivChange=view.findViewById(R.id.ivChange);
        tvBalance=view.findViewById(R.id.tvBalance);
        tvNickName=view.findViewById(R.id.tvNickName);
        tvSliverIntegral=view.findViewById(R.id.tvSliverIntegral);
        llRelativeUs=view.findViewById(R.id.llRelativeUs);
        tvAllOrder=view.findViewById(R.id.tvAllOrder);
        llFeedBack=view.findViewById(R.id.llFeedBack);
        llMyExtendStore=view.findViewById(R.id.llMyExtendStore);
        llAddressManager=view.findViewById(R.id.llAddressManager);
        llIntegralSilver=view.findViewById(R.id.llIntegralSilver);
        llServiceCenter=view.findViewById(R.id.llServiceCenter);
        llApplyStore=view.findViewById(R.id.llApplyStore);
        llApplyTeam=view.findViewById(R.id.llApplyTeam);
        llMyQrCode=view.findViewById(R.id.llMyQrCode);
        llCoupon=view.findViewById(R.id.llCoupon);
        ivAvatar=view.findViewById(R.id.ivAvatar);
        llSign=view.findViewById(R.id.llSign);
        llSign.setOnClickListener(this::onClick);
        llCoupon.setOnClickListener(this::onClick);
        llMyQrCode.setOnClickListener(this::onClick);
        llApplyTeam.setOnClickListener(this::onClick);
        llIntegralSilver.setOnClickListener(this::onClick);
        ivSet.setOnClickListener(this::onClick);
        llApplyStore.setOnClickListener(this::onClick);
        llMyProperty.setOnClickListener(this::onClick);
        llMyExtendStore.setOnClickListener(this::onClick);
        tvNickName.setOnClickListener(this::onClick);
        llFeedBack.setOnClickListener(this::onClick);
        llRelativeUs.setOnClickListener(this::onClick);
        llServiceCenter.setOnClickListener(this::onClick);
        llAddressManager.setOnClickListener(this::onClick);
        tvAllOrder.setOnClickListener(this::onClick);
        ivChange.setOnClickListener(this::onClick);
    }
}